package com.keymozy.controller;

import com.keymozy.pojo.Menu;
import com.keymozy.pojo.Staff;
import com.keymozy.service.MenuService;
import com.keymozy.state.Code;
import com.keymozy.state.RespData;
import com.keymozy.util.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/menu")
@CrossOrigin
public class MenuController {
    @Autowired
    private MenuService menuService;

    @GetMapping("/getMenu")
    public RespData getMenu(){
        log.info("正在获取菜单");
        Staff staff = (Staff) TokenUtil.data.get();
        if (staff==null){
            return new RespData(Code.FALSE_MENU_1,menuService.getMenu(staff));
        }
        return new RespData(Code.SUCCESS_MENU_1,menuService.getMenu(staff));
    }
    @GetMapping("/listmenu")
    public RespData listMenu(){
        return new RespData(Code.SUCCESS_SEARCH,menuService.listMenu());
    }
    @PostMapping
    public RespData delMenus(@RequestBody List<Integer> ids){
        boolean b = menuService.removeByIds(ids);
        if(b){
            return new RespData(Code.SUCCESS_DELETE_1,"删除成功");
        }
        return new RespData(Code.FALSE_DELETE,"删除失败");
    }
}
